package com.jason.kotlin.meta.architecture2.repository

import com.jason.kotlin.meta.architecture2.api.UserService
import com.jason.kotlin.meta.architecture2.model.UserBean
import com.jason.kotlin.meta.architecture2.model.WanApiResponse

/**
 * 用户相关api的数据获取实现
 *
 * @property userService UserService
 * @constructor
 */
class UserApiImpl(private val userService: UserService) : UserApi {

    companion object{
        const val KEY_USER_NAME = "username"
        const val KEY_PASSWORD = "password"
        const val KEY_RE_PASSWORD = "repassword"
    }

    override suspend fun login(username: String, password: String): WanApiResponse<UserBean> =
        userService.login(username, password)

    override suspend fun register(username: String, password: String, repassword:String): WanApiResponse<Any> {
        val map = HashMap<String, String>()
        map[KEY_USER_NAME] = username
        map[KEY_PASSWORD] = password
        map[KEY_RE_PASSWORD] = repassword
        return userService.register(map)
    }


    override suspend fun logout(): WanApiResponse<Any?> = userService.logout()
}